package idiet.service;

import idiet.bean.Customer;
import idiet.bean.CustomerNurse;
import idiet.dao.hibernate.CustomerDao;
import idiet.dao.hibernate.CustomerNurseDao;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service("customerNurseService")
public class CustomerNurseService {
	@Autowired
	CustomerNurseDao customerNurseDao;
	@Autowired
	CustomerDao customerDao;
	public CustomerNurse getCustomerNurse(int customerNurseId){
		return this.customerNurseDao.getCustomerNurseByCustomerNurseId(customerNurseId);
	}
	public CustomerNurse getCustomerNurse4LastByCustomer(Customer customer){
		return this.customerNurseDao.getCustomerNurse4LastByCustomer(customer);
	}
	public List<CustomerNurse> getCustomerNurses(){
		return this.customerNurseDao.getCustomerNurses();
	}
	public List<CustomerNurse> getCustomerNurses(Customer customer){
		if(customer==null){
			return this.customerNurseDao.getCustomerNurses();
		}else{
			return this.customerNurseDao.getCustomerNursesByCustomer(customer);
		}
	}
	public List<CustomerNurse> getCustomerNurses(String customerName){
		List<Customer> customers=null;
		if(customerName==null){
			customers=this.customerDao.getCustomers();
		}else{
			customers=this.customerDao.getCustomersByCustomerName(customerName);
		}
		if(customers==null){
			return this.customerNurseDao.getCustomerNurses();
		}else{
			return this.customerNurseDao.getCustomerNurses(customers);
		}
	}
	public List<CustomerNurse> getCustomerNurses(Date lmTimestampStart,Date lmTimestampEnd){
		return this.customerNurseDao.getCustomerNurses(lmTimestampStart, lmTimestampEnd);
	}
	public List<CustomerNurse> getCustomerNurses(String customerName,Date lmTimestampStart,Date lmTimestampEnd){
		List<Customer> customers=null;
		if(customerName==null){
			return this.customerNurseDao.getCustomerNurses(lmTimestampStart, lmTimestampEnd);
		}else{
			customers=this.customerDao.getCustomersByCustomerName(customerName);
			return this.customerNurseDao.getCustomerNurses(customers, lmTimestampStart, lmTimestampEnd);
		}
	}
	public List<CustomerNurse> getCustomerNurses(Customer customer,Date lmTimestampStart,Date lmTimestampEnd){
		if(customer==null){
			return this.customerNurseDao.getCustomerNurses(lmTimestampStart, lmTimestampEnd);
		}else{
			return this.customerNurseDao.getCustomerNurses(customer, lmTimestampStart, lmTimestampEnd);
		}
	}
	public void createCustomerNurse(CustomerNurse nurse){
		this.customerNurseDao.createCustomerNurse(nurse);
	}
	
}
